from apps.common.base.serializers import *
from apps.system.admin.models import Admin
from apps.system.user.models import User

class AdminBaseSerializer(BaseSerializer):
    class Meta:
        model = Admin
        fields = "__all__"


class AdminModelSerializer(AdminBaseSerializer):

    roleModel = serializers.SerializerMethodField()
    def get_roleModel(self, obj):
        try:
            return {'id': obj.role.id, 'name': obj.role.name, 'key': obj.role.key}
        except:
            return {}

    username = serializers.SerializerMethodField()
    def get_username(self, obj):
        if obj.account:
            return obj.account.username
        else:
            return ''
    
    class Meta:
        model = Admin
        fields = "__all__"